/*
 *
 * Copyright (C) 2012 Walter Lütgenau
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package offset.nodes.server.view.list;

import offset.nodes.Constants;

/**
 *
 * @author Walter Lütgenau
 */
public class DefaultColumnManager implements ColumnInfo {
    static String[] IGNORE_COLUMNS = new String[] {Constants.JCR_SCORE, Constants.JCR_PATH};
    String[] availableColumns;
    String[] selectedColumns;

    public DefaultColumnManager(String[] availableColumns) {
        this.availableColumns = availableColumns;
        
        this.selectedColumns = new String[availableColumns.length-IGNORE_COLUMNS.length];
        int selected = 0;
        for( String column: availableColumns) {
            boolean ignore = false;
            for(String pseudo: IGNORE_COLUMNS)
                if ( column.equals(pseudo))
                    ignore = true;
            
            if ( !ignore)
                selectedColumns[selected++] = column;
        }
    }

    public DefaultColumnManager(String[] availableColumns, String[] selectedColumns) {
        this.availableColumns = availableColumns;
        this.selectedColumns = selectedColumns;
    }

    public String[] getAvailableColumns() {
        return availableColumns;
    }

    public void setAvailableColumns(String[] availableColumns) {
        this.availableColumns = availableColumns;
    }

    public String[] getSelectedColumns() {
        return selectedColumns;
    }

    public void setSelectedColumns(String[] columns) {
        this.selectedColumns = columns;
    }
    
    public String[] getPseudoColumns() {
        return IGNORE_COLUMNS;
    }
}
